class Solution(object):

    def topStudents(self, positive_feedback, negative_feedback, report, student_id, k):
        """
        :type positive_feedback: List[str]
        :type negative_feedback: List[str]
        :type report: List[str]
        :type student_id: List[int]
        :type k: int
        :rtype: List[int]
        """
        if len(report) != len(student_id):
            raise Exception("wrong param")
        positive_feedback = set(positive_feedback)
        negative_feedback = set(negative_feedback)

        student_score = []
        for i in range(0, len(report)):
            words = report[i].split(" ")
            current_score = 0
            for word in words:
                if word in positive_feedback:
                    current_score = current_score + 3
                elif word in negative_feedback:
                    current_score = current_score - 1
            student_score.append((current_score, student_id[i]))

        sorted_student_score = sorted(student_score, key=lambda x: (x[0], -x[1]), reverse=True)

        top_k_student = []
        for i in range(0, k):
            top_k_student.append(sorted_student_score[i][1])

        return top_k_student
